/* eslint-disable */
import { _decorator } from 'cc';
import { CallBackHandler } from '../PoolObj/CallBackHandler';
import { EventType, ShareEvent } from '../../../Game/Config/GameEnum';
import { EventManager } from '../../Manager/EventManager';
import { VideoEvent } from '../../../Data/Types';
const { ccclass } = _decorator;
export enum RecordType {
  START = 'Start',
  PAUSE = 'Pause',
  RESUME = 'Resume',
  STOP = 'Stop',
  DESTROY = 'Destroy',
}

@ccclass
/**
 * 多平台抽象类
 */
export default class PlatformBase {
  platformApi: any;
  $bannerAd: any;
  $bannerInit: boolean;
  $videoAd: any;
  $insertAd: any;

  $adIndex: VideoEvent;
  $shareIndex: ShareEvent;

  $videoId: string;
  $bannerId: string;
  $insertId: string;
  $appCode: string;
  /** 平台初始化 */
  initFramework() {
    EventManager.Ins().emit(EventType.LOGIN);
  }
  /** 短震动 */
  openVibrateShort() {}
  /** 长震动 */
  openVibrateLong(t) {}
  /** 桌面图标 */
  sendDesktop(e) {}
  /** 调起添加桌面图标 */
  hasShortcutInstalled(e) {}
  /** 是否已添加桌面图标 */
  getIsDesktop() {}
  /** 播放音乐 */
  playMusic(e, t) {}
  /** 暂停音乐播放 */
  stopMusic() {}
  /** 播放音效 */
  playSound(e, t) {}
  /** 暂停音效 */
  stopSound(e) {}
  /** 退出游戏 */
  exitGame() {}
  /** 提示窗口 */
  showToast(e, i, d) {}
  createLupingBtn() {}
  createMoreGameBtn() {}
  addShortcut() {}
  checkShortcut() {}

  showBanner(e) {}
  openBanner(e) {}
  hideBanner() {}
  adFinish() {
    let eId = null;
    switch (this.$adIndex) {
      case VideoEvent.AddItem:
        eId = EventType.AD_GETITEM;
        break;
      case VideoEvent.UnlockVisitor:
        eId = EventType.AD_VISITOR;
        break;
      case VideoEvent.UnlockGrid:
        eId = EventType.AD_GRID;
        break;
      case VideoEvent.Revive:
        eId = EventType.AD_REVIVE;
        break;
    }
    EventManager.Ins().emit(eId);
  }
  showVideo(index: VideoEvent) {
    this.$adIndex = index;
    this.adFinish();
  }
  showInsertAd() {}
  loadNativeAd(e) {}
  showNativeInBox(e, t, i) {}
  showNativeInsert(e, t) {}
  showNativeInsertAd(e, i, a) {}
  showNativeBannerAd(e, i, a) {}
  showSmallNative(e) {}
  recordScreen() {}
  removeScreen() {}
  pauseRecord() {}
  showTTBanner(e) {}
  reportRankingList(e) {}
  getRankingList() {}
  showQQBox() {}
  navigateToVideo(e) {}
  jumpToDY() {}
  loadSubpackage(e, t) {}
  showElectPortalAd(e) {}
  showwxCustomAd(e, t) {}
  openContent(e, t) {}
  closeContent() {}
  showNativeIcon(e, t) {}
  showNativeBanner(e, t) {}
  showPlayBanner(e) {}
  getHttpId() {}
  onHasShortcutInstalled(e) {}
  /** 埋点上报 */
  trackEvent(e, o = null) {}
  AutoRecord(type: string) {}
  checkScene() {}
  navigateToScene() {}

  shareFinish() {
    let key = '';
    switch (this.$shareIndex) {
      case ShareEvent.Energy:
        break;
    }
    if (key != '') EventManager.Ins().emit(ShareEvent.Energy);
  }
  shareEnergy(e) {
    this.$shareIndex = e;
    this.shareFinish();
  }
  shareMessage() {}
  /** http请求 */
  requestHttpGet(
    url: string,
    data: any,
    callback: CallBackHandler,
    headers: { [key: string]: string } = {
      'Content-Type': 'application/json',
    }
  ) {
    if (data) {
      url += '?';
      for (const key in data) {
        url += `${key}=${data[key]}&`;
      }
      url = url.slice(0, -1);
    }
    fetch(url, {
      method: 'GET',
      headers: headers,
    })
      .then((response) => response.text())
      .then((result) => {
        try {
          result = JSON.parse(result);
        } catch {
          result = null;
        }
        callback?.execute(result);
      })
      .catch((error) => console.log('error', error));
  }

  /** http请求 */
  requestHttpPost(
    url: string,
    data: any,
    callback: CallBackHandler,
    headers: { [key: string]: string } = {
      'Content-Type': 'application/json',
    }
  ) {
    fetch(url, {
      method: 'POST',
      headers: headers ? headers : {},
      body: JSON.stringify(data),
    })
      .then((response) => response.text())
      .then((result) => {
        try {
          result = JSON.parse(result);
        } catch {
          result = null;
        }
        callback?.execute(result);
      })
      .catch((error) => console.log('error', error));
  }
}
